<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>

</head>
<body>
<div style="text-align: center;margin-top: 20px">
    <fome>
        账号：<input type="text" id="name" placeholder="用户名"><br>
        密码：<input type="text" id="pwd" placeholder="密码"><br>
        <div style="margin-top: 10px" id="status">身份:
            <label><input type="radio" name="sex" value="1">老师</label>
            <label><input type="radio" name="sex" value="2">学生</label>
        </div>
        <input type="button" value="注册" id="btn" style="margin-top: 10px;width: 5%">
        <input type="button" value="登录" id="btn1" style="margin-top: 10px;width: 5%">
    </fome>

</div>
</body>
<script>
    $("#btn").click(function () {
        var name=$("#name").val();
        var pwd=$("#pwd").val();
        var sex= $("input[name='sex']:checked").val();
        var json={
            "name":name,
            "pwd":pwd,
            "sex":sex
        }
        insert(json);
    })
    $("#btn1").click(function () {
        window.location.href="/";
    })

    function insert(json){
        $.ajax({
            type: "GET",
            url: "http://localhost:8888/insert1",
            headers: {
                "Content-Type": "application/x-www-form-urlencoded",
            },
            data: json,
            dataType: "json",
            success: function(data){
                if (data.code == 200) {
                    alert(data.msg);
                    window.location.href = "home";
                } else {
                    alert(data.msg);
                }
            }
        });
    }
</script>
</html>